
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Thay đổi thông tin nhân viên</h1>
        </div>
    </div>
    <?php
    //if ($resultstatus) {
    ?>
    <!--        <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-success">
                        <div class="panel-heading">
    <?php echo $resultstatus; ?>
                        </div>
                    </div>
                </div>
            </div>-->
    <?php //} ?>

    <div class="row">
        <?php if ($message) { ?>
            <div class="col-lg-12">
                <div class="alert alert-<?php echo $messageType; ?> alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $message; ?>
                </div>
            </div>
        <?php } ?>
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Thông tin nhân viên
                </div>
                <div class="panel-body">
                    <form method="post" action="<?php echo site_url(get_folder($loggedUser['title']) . '/users2/edit/' . $editUser['id']); ?>">
                        <input type="hidden" name="Command" value="Edit" />
                        <div class="row">
                            <!--Cột trái-->
                            <div class="col-lg-6">
                                <div class="form-group <?php echo (form_error('username') != '' ? 'has-error' : ''); ?>">
                                    <label>Code/Username</label>
                                    <input class="form-control" type="text" name="username" value="<?php echo $editUser['code']; ?>" readonly="readonly" >
                                    <?php print(form_error('username', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('password') != '' ? 'has-error' : ''); ?>">
                                    <label>Password (không bắt buộc)</label>
                                    <input class="form-control" type="password" name="password" autocomplete="off" > 
                                    <?php print(form_error('password', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('name') != '' ? 'has-error' : ''); ?>">
                                    <label>Full name</label>
                                    <input class="form-control" type="text" name="name" value="<?php echo $editUser['name']; ?>"> 
                                    <?php print(form_error('name', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">
                                    <label>Title</label>
                                    <select name="title" id="title_name" class="form-control">
                                        <?php foreach ($titles as $each) { ?>
                                            <option <?php echo ($editUser['title'] == $each) ? 'selected="selected"' : ''; ?>  value="<?php echo $each; ?>"><?php echo $each; ?></option>
                                        <?php }
                                        ?>
                                    </select>
                                    <p class="help-block">Khi thay đổi Title, bạn cần bấm nút "Lưu thay đổi" để cập nhật các giá trị RSM, Supervisor, Team leader.</p>
                                </div>
                                <div class="form-group">
                                    <label>Nhóm làm bài trắc nghiệm</label>
                                    <select name="gid" class="form-control">
                                        <option value=""></option>
                                        <?php foreach ($groups as $eachGroup) { ?>
                                            <option <?php echo ($editUser['gid'] == $eachGroup['gid']) ? 'selected="selected"' : ''; ?> value="<?php echo $eachGroup['gid']; ?>"><?php echo $eachGroup['group_name']; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="form-group <?php echo (form_error('location') != '' ? 'has-error' : ''); ?>" >
                                    <label>Location</label>
                                    <input class="form-control" value="<?php echo $editUser['location']; ?>" type="text" name="location" autocomplete="off"> 
                                    <?php print(form_error('location', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('starting_day') != '' ? 'has-error' : ''); ?>" >
                                    <label>Start day</label>
                                    <input class="form-control datepicker" id="datepicker" type="text" name="starting_day" value="<?php if ($editUser['starting_day']) echo date("Y/m/d", strtotime($editUser['starting_day'])); ?>"> 
                                    <?php print(form_error('starting_day', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('stopping_day') != '' ? 'has-error' : ''); ?>" >
                                    <label>Stop day</label>
                                    <input class="form-control datepicker" type="text" name="stopping_day" value="<?php
                                    if ($editUser['stopping_day']) {
                                        echo date("Y/m/d", strtotime($editUser['stopping_day']));
                                    } else {
                                        echo '';
                                    }
                                    ?>"> 
                                           <?php print(form_error('stopping_day', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">

                                    <label>RSM</label>
                                    <select name="rsm_code" class="form-control">
                                        <?php if ($editUser['title'] == 'SD' || $editUser['title'] == 'HR' || $editUser['title'] == 'SC' || $editUser['title'] == 'RSM' || $editUser['title'] == 'KAM') { ?>
                                            <option value="">&nbsp;</option>
                                        <?php } else { ?>
                                            <option value="">&nbsp;</option>
                                            <?php foreach ($rsms as $eachRsm) { ?>
                                                <option <?php echo ($editUser['rsm_code'] == $eachRsm['code']) ? 'selected="selected"':''; ?> value="<?php echo $eachRsm['code']; ?>"><?php echo $eachRsm['code'] .' - '. $eachRsm['name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="form-group">

                                    <label>Supervisor</label>
                                    <select name="supervisor_code" class="form-control">
                                        <?php if ($editUser['title'] == 'SD' || $editUser['title'] == 'HR' || $editUser['title'] == 'SC' || $editUser['title'] == 'RSM' || $editUser['title'] == 'KAM' || $editUser['title'] == 'SS' || $editUser['title'] == 'KAS') { ?>
                                            <option value="">&nbsp;</option>
                                        <?php } else { ?>
                                            <option value="">&nbsp;</option>
                                            <?php foreach ($supervisors as $each) { ?>
                                                <option <?php echo ($editUser['supervisor_code'] == $each['code']) ? 'selected="selected"':''; ?> value="<?php echo $each['code']; ?>"><?php echo $each['code'] .' - '. $each['name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="form-group">

                                    <label>Team leader</label>
                                    <select name="teamleader_code" class="form-control">
                                        <?php if ($editUser['title'] == 'SD' || $editUser['title'] == 'HR' || $editUser['title'] == 'SC' || $editUser['title'] == 'RSM' || $editUser['title'] == 'KAM' || $editUser['title'] == 'SS' || $editUser['title'] == 'KAS' || $editUser['title'] == 'NRTL' || $editUser['title'] == 'BSTL' || $editUser['title'] == 'PGTL' ) { ?>
                                            <option value="">&nbsp;</option>
                                        <?php } else { ?>
                                            <option value="">&nbsp;</option>
                                            <?php foreach ($teamleaders as $each) { ?>
                                                <option <?php echo ($editUser['teamleader_code'] == $each['code']) ? 'selected="selected"':''; ?> value="<?php echo $each['code']; ?>"><?php echo $each['code'] .' - '. $each['name']; ?></option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>

                            <!--Cột phải-->
                            <div class="col-lg-6">

                                <div class="form-group <?php echo (form_error('identity_number') != '' ? 'has-error' : ''); ?>" >
                                    <label>Identity No</label>
                                    <input class="form-control" value="<?php echo $editUser['identity_number']; ?>" type="text" name="identity_number" autocomplete="off"> 
                                    <?php print(form_error('identity_number', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('address') != '' ? 'has-error' : ''); ?>" >
                                    <label>Address</label>
                                    <textarea class="form-control" type="text" name="address" autocomplete="off"><?php echo $editUser['address']; ?></textarea>
                                    <?php print(form_error('address', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('phone') != '' ? 'has-error' : ''); ?>" >
                                    <label>Phone</label>
                                    <input class="form-control" value="<?php echo $editUser['phone']; ?>" type="text" name="phone" autocomplete="off"> 
                                    <?php print(form_error('phone', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('email') != '' ? 'has-error' : ''); ?>" >
                                    <label>Email</label>
                                    <input class="form-control" type="text" name="email" value="<?php echo $editUser['email']; ?>"> 
                                    <?php print(form_error('email', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">
                                    <label>Status</label>
                                    <select name="status" class="form-control">
                                        <option <?php echo ($editUser['status'] == "active") ? 'selected="selected"' : ''; ?>  value="active">Active</option> 
                                        <option <?php echo ($editUser['status'] == "inactive") ? 'selected="selected"' : ''; ?> value="inactive">Inactive</option>
                                        <option <?php echo ($editUser['status'] == "pregnant") ? 'selected="selected"' : ''; ?> value="pregnant">Pregnant</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>Status 2</label>
                                    <select name="status2" class="form-control">
                                        <option <?php echo ($editUser['status2'] == null) ? 'selected="selected"' : ''; ?>  value=""></option> 
                                        <option <?php echo ($editUser['status2'] == "active") ? 'selected="selected"' : ''; ?>  value="active">Active</option> 
                                        <option <?php echo ($editUser['status2'] == "inactive") ? 'selected="selected"' : ''; ?> value="inactive">Inactive</option>
                                        <option <?php echo ($editUser['status2'] == "pregnant") ? 'selected="selected"' : ''; ?> value="pregnant">Pregnant</option>
                                    </select>
                                </div>
                                <div class="form-group <?php echo (form_error('note') != '' ? 'has-error' : ''); ?>" >
                                    <label>Note</label>
                                    <textarea class="form-control" type="text" name="note" autocomplete="off"><?php echo $editUser['note']; ?></textarea>
                                    <?php print(form_error('note', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                
                                <?php if($editUser['title'] == 'RSM' || $editUser['title'] == 'KAM' || $editUser['title'] == 'SS' || $editUser['title'] == 'KAS'){ ?>
                                <div class="form-group <?php echo (form_error('replace') != '' ? 'has-error' : ''); ?>" >
                                    <label>Thay thế cho</label>
                                    <select name="replace" class="form-control">
                                        <option value="noreplace"></option> 
                                        <?php foreach ($editUser['canReplace'] as $eachPerson) { ?>
                                        <option value="<?php echo $eachPerson['code'] ?>"><?php echo $eachPerson['title'].' - '.$eachPerson['code'].' - '.$eachPerson['name'] ?></option>
                                        <?php } ?>
                                    </select>
                                    <?php print(form_error('note', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <?php } ?>

                                <?php
                                if ($su == "1") {
                                    ?>
                                    <div class="form-group">
                                        <label>Account Type</label>

                                        <select name="account_type" class="form-control">
                                            <option <?php
                                            if ($editUser['su'] == "0") {
                                                echo "selected";
                                            }
                                            ?> value="0">User</option>
                                            <option <?php
                                            if ($editUser['su'] == "1") {
                                                echo "selected";
                                            }
                                            ?> value="1">Administrator</option>
                                        </select>
                                    </div>
                                    <?php
                                }
                                ?>
                                <br>

                            </div>
                            
                            <div class="col-lg-6">&nbsp;</div>
                            
                            <div class="col-lg-6">
                                <input class="btn btn-primary" type="submit" value="Lưu thay đổi"> &nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="<?php echo $PreviousUrl ?>">Quay lại danh sách</a>
                                <input type="hidden" name="PreviousUrl" value="<?php echo set_value('PreviousUrl', $PreviousUrl); ?>" />
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- /#page-wrapper -->
<script type="text/javascript" src="<?php echo base_url(); ?>/js/ajax.js" ></script>
<script type="text/javascript">

    $(document).ready(function() {
        $(".datepicker").datepicker({
            dateFormat: 'yy/mm/dd',
            yearRange: "-10:+0",
            changeYear: true,
            changeMonth: true

        });
    });
</script>


<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>